<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>MiXiM: D:/Projects/MiXiM/extsrc/mixim/src/modules/mac/BMacLayer.h Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>


</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">MiXiM
   &#160;<span id="projectnumber">2.3</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li><a href="dirs.html"><span>Directories</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('a00424.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">BMacLayer.h</div>  </div>
</div>
<div class="contents">
<div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">//</span>
<a name="l00002"></a>00002 <span class="comment">// This program is free software: you can redistribute it and/or modify</span>
<a name="l00003"></a>00003 <span class="comment">// it under the terms of the GNU Lesser General Public License as published by</span>
<a name="l00004"></a>00004 <span class="comment">// the Free Software Foundation, either version 3 of the License, or</span>
<a name="l00005"></a>00005 <span class="comment">// (at your option) any later version.</span>
<a name="l00006"></a>00006 <span class="comment">// </span>
<a name="l00007"></a>00007 <span class="comment">// This program is distributed in the hope that it will be useful,</span>
<a name="l00008"></a>00008 <span class="comment">// but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<a name="l00009"></a>00009 <span class="comment">// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<a name="l00010"></a>00010 <span class="comment">// GNU Lesser General Public License for more details.</span>
<a name="l00011"></a>00011 <span class="comment">// </span>
<a name="l00012"></a>00012 <span class="comment">// You should have received a copy of the GNU Lesser General Public License</span>
<a name="l00013"></a>00013 <span class="comment">// along with this program.  If not, see http://www.gnu.org/licenses/.</span>
<a name="l00014"></a>00014 <span class="comment">// </span>
<a name="l00015"></a>00015 
<a name="l00016"></a>00016 <span class="preprocessor">#ifndef BMACLAYER_H_</span>
<a name="l00017"></a>00017 <span class="preprocessor"></span><span class="preprocessor">#define BMACLAYER_H_</span>
<a name="l00018"></a>00018 <span class="preprocessor"></span>
<a name="l00019"></a>00019 <span class="preprocessor">#include &lt;string&gt;</span>
<a name="l00020"></a>00020 <span class="preprocessor">#include &lt;sstream&gt;</span>
<a name="l00021"></a>00021 <span class="preprocessor">#include &lt;vector&gt;</span>
<a name="l00022"></a>00022 <span class="preprocessor">#include &lt;list&gt;</span>
<a name="l00023"></a>00023 
<a name="l00024"></a>00024 <span class="preprocessor">#include &quot;MiXiMDefs.h&quot;</span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &quot;BaseMacLayer.h&quot;</span>
<a name="l00026"></a>00026 <span class="preprocessor">#include &lt;DroppedPacket.h&gt;</span>
<a name="l00027"></a>00027 
<a name="l00028"></a>00028 <span class="keyword">class </span>MacPkt;
<a name="l00029"></a>00029 
<a name="l00059"></a><a class="code" href="a00035.html">00059</a> <span class="keyword">class </span>MIXIM_API <a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a> : <span class="keyword">public</span> <a class="code" href="a00026.html" title="A very simple MAC module template which provides de- and encapsulation of messages using the standard...">BaseMacLayer</a>
<a name="l00060"></a>00060 {
<a name="l00061"></a>00061   <span class="keyword">private</span>:
<a name="l00064"></a>00064   <a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a>(<span class="keyword">const</span> <a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a>&amp;);
<a name="l00067"></a>00067   <a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a>&amp; <a class="code" href="a00026.html#aac78343ae4c96940669323e51ec09ada" title="Assignment operator is not allowed.">operator=</a>(<span class="keyword">const</span> <a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a>&amp;);
<a name="l00068"></a>00068 
<a name="l00069"></a>00069   <span class="keyword">public</span>:
<a name="l00070"></a>00070   <a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a>()
<a name="l00071"></a>00071     : <a class="code" href="a00026.html" title="A very simple MAC module template which provides de- and encapsulation of messages using the standard...">BaseMacLayer</a>()
<a name="l00072"></a>00072     , macQueue()
<a name="l00073"></a>00073     , nbTxDataPackets(0), nbTxPreambles(0), nbRxDataPackets(0), nbRxPreambles(0)
<a name="l00074"></a>00074     , nbMissedAcks(0), nbRecvdAcks(0), nbDroppedDataPackets(0), nbTxAcks(0)
<a name="l00075"></a>00075     , macState(INIT)
<a name="l00076"></a>00076     , resend_data(NULL), ack_timeout(NULL), start_bmac(NULL), wakeup(NULL)
<a name="l00077"></a>00077     , send_ack(NULL), cca_timeout(NULL), ack_tx_over(NULL), send_preamble(NULL), stop_preambles(NULL)
<a name="l00078"></a>00078     , data_tx_over(NULL), data_timeout(NULL)
<a name="l00079"></a>00079     , lastDataPktSrcAddr()
<a name="l00080"></a>00080     , lastDataPktDestAddr()
<a name="l00081"></a>00081     , txAttempts(0)
<a name="l00082"></a>00082     , droppedPacket()
<a name="l00083"></a>00083     , nicId(-1)
<a name="l00084"></a>00084     , queueLength(0)
<a name="l00085"></a>00085     , animation(<span class="keyword">false</span>)
<a name="l00086"></a>00086     , slotDuration(0), bitrate(0), checkInterval(0), txPower(0)
<a name="l00087"></a>00087     , useMacAcks(0)
<a name="l00088"></a>00088     , maxTxAttempts(0)
<a name="l00089"></a>00089     , stats(<span class="keyword">false</span>)
<a name="l00090"></a>00090   {}
<a name="l00091"></a>00091   <span class="keyword">virtual</span> ~<a class="code" href="a00035.html" title="Implementation of B-MAC (called also Berkeley MAC, Low Power Listening or LPL).">BMacLayer</a>();
<a name="l00092"></a>00092 
<a name="l00094"></a>00094     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a61c82dc3b225eac37f7fa9936c28c2c3" title="Initialization of the module and some variables.">initialize</a>(<span class="keywordtype">int</span>);
<a name="l00095"></a>00095 
<a name="l00097"></a>00097     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00025.html#a5ab11502dbeeea89693d29841376a2f7" title="Called when the simulation has finished.">finish</a>();
<a name="l00098"></a>00098 
<a name="l00100"></a>00100     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a413375cec02b990a521b62086a02264c">handleLowerMsg</a>(cMessage*);
<a name="l00101"></a>00101 
<a name="l00103"></a>00103     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a6de2ca07018de313a7147a03e6d77bff" title="Handle messages comming from the network layer.">handleUpperMsg</a>(cMessage*);
<a name="l00104"></a>00104 
<a name="l00106"></a>00106     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#add5277c1a60dab10db40c8d9641e48c4" title="Handle self messages such as timer...">handleSelfMsg</a>(cMessage*);
<a name="l00107"></a>00107 
<a name="l00109"></a>00109     <span class="keyword">virtual</span> <span class="keywordtype">void</span> <a class="code" href="a00026.html#a796d456d593dfab3188b37e506dd76a8" title="Handle control messages from lower layer.">handleLowerControl</a>(cMessage *msg);
<a name="l00110"></a>00110 
<a name="l00111"></a>00111   <span class="keyword">protected</span>:
<a name="l00112"></a>00112     <span class="keyword">typedef</span> std::list&lt;macpkt_ptr_t&gt; MacQueue;
<a name="l00113"></a>00113 
<a name="l00116"></a><a class="code" href="a00035.html#ae34984aa9d79ca356e9d310cf7fe431e">00116</a>     MacQueue <a class="code" href="a00035.html#ae34984aa9d79ca356e9d310cf7fe431e" title="A queue to store packets from upper layer in case another packet is still waiting for transmission...">macQueue</a>;
<a name="l00117"></a>00117 
<a name="l00120"></a>00120   <span class="keywordtype">long</span> nbTxDataPackets;
<a name="l00121"></a>00121   <span class="keywordtype">long</span> nbTxPreambles;
<a name="l00122"></a>00122   <span class="keywordtype">long</span> nbRxDataPackets;
<a name="l00123"></a>00123   <span class="keywordtype">long</span> nbRxPreambles;
<a name="l00124"></a>00124   <span class="keywordtype">long</span> nbMissedAcks;
<a name="l00125"></a>00125   <span class="keywordtype">long</span> nbRecvdAcks;
<a name="l00126"></a>00126   <span class="keywordtype">long</span> nbDroppedDataPackets;
<a name="l00127"></a>00127   <span class="keywordtype">long</span> nbTxAcks;
<a name="l00150"></a><a class="code" href="a00035.html#aeed53f8e3ce2313f84d47dd7226f1a9f">00150</a>   <span class="keyword">enum</span> <a class="code" href="a00035.html#aeed53f8e3ce2313f84d47dd7226f1a9f" title="MAC states.">States</a> {
<a name="l00151"></a>00151     INIT, <span class="comment">//0</span>
<a name="l00152"></a>00152     SLEEP,  <span class="comment">//1</span>
<a name="l00153"></a>00153     CCA,  <span class="comment">//2</span>
<a name="l00154"></a>00154     SEND_PREAMBLE,  <span class="comment">//3</span>
<a name="l00155"></a>00155     WAIT_DATA,    <span class="comment">//4</span>
<a name="l00156"></a>00156     SEND_DATA,    <span class="comment">//5</span>
<a name="l00157"></a>00157     WAIT_TX_DATA_OVER,  <span class="comment">//6</span>
<a name="l00158"></a>00158     WAIT_ACK,   <span class="comment">//7</span>
<a name="l00159"></a>00159     SEND_ACK,   <span class="comment">//8</span>
<a name="l00160"></a>00160     WAIT_ACK_TX   <span class="comment">//9</span>
<a name="l00161"></a>00161     };
<a name="l00163"></a><a class="code" href="a00035.html#a3f547e9f97f0c07b692c32c4183c5411">00163</a>   <a class="code" href="a00035.html#aeed53f8e3ce2313f84d47dd7226f1a9f" title="MAC states.">States</a> <a class="code" href="a00035.html#a3f547e9f97f0c07b692c32c4183c5411" title="The current state of the protocol.">macState</a>;
<a name="l00164"></a>00164 
<a name="l00167"></a><a class="code" href="a00035.html#a7d56487b9b46428d6c225ad59cf1e1cf">00167</a>   <span class="keyword">enum</span> <a class="code" href="a00035.html#a7d56487b9b46428d6c225ad59cf1e1cf" title="Types of messages (self messages and packets) the node can process.">TYPES</a> {
<a name="l00168"></a>00168     <span class="comment">// packet types</span>
<a name="l00169"></a>00169     BMAC_PREAMBLE = 191,
<a name="l00170"></a>00170     BMAC_DATA,
<a name="l00171"></a>00171     BMAC_ACK,
<a name="l00172"></a>00172     <span class="comment">// self message types</span>
<a name="l00173"></a>00173     BMAC_RESEND_DATA,
<a name="l00174"></a>00174     BMAC_ACK_TIMEOUT,
<a name="l00175"></a>00175     BMAC_START_BMAC,
<a name="l00176"></a>00176     BMAC_WAKE_UP,
<a name="l00177"></a>00177     BMAC_SEND_ACK,
<a name="l00178"></a>00178     BMAC_CCA_TIMEOUT,
<a name="l00179"></a>00179     BMAC_ACK_TX_OVER,
<a name="l00180"></a>00180     BMAC_SEND_PREAMBLE,
<a name="l00181"></a>00181     BMAC_STOP_PREAMBLES,
<a name="l00182"></a>00182     BMAC_DATA_TX_OVER,
<a name="l00183"></a>00183     BMAC_DATA_TIMEOUT
<a name="l00184"></a>00184   };
<a name="l00185"></a>00185 
<a name="l00186"></a>00186   <span class="comment">// messages used in the FSM</span>
<a name="l00187"></a>00187   cMessage *resend_data;
<a name="l00188"></a>00188   cMessage *ack_timeout;
<a name="l00189"></a>00189   cMessage *start_bmac;
<a name="l00190"></a>00190   cMessage *wakeup;
<a name="l00191"></a>00191   cMessage *send_ack;
<a name="l00192"></a>00192   cMessage *cca_timeout;
<a name="l00193"></a>00193   cMessage *ack_tx_over;
<a name="l00194"></a>00194   cMessage *send_preamble;
<a name="l00195"></a>00195   cMessage *stop_preambles;
<a name="l00196"></a>00196   cMessage *data_tx_over;
<a name="l00197"></a>00197   cMessage *data_timeout;
<a name="l00198"></a>00198 
<a name="l00201"></a>00201   <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> lastDataPktSrcAddr;
<a name="l00202"></a>00202   <a class="code" href="a00117.html#aea56b60dcb5ae8c2bde465271daf7210" title="Type definition for a L2 (MAC) address.">LAddress::L2Type</a> lastDataPktDestAddr;
<a name="l00203"></a>00203   <span class="keywordtype">int</span>              txAttempts;
<a name="l00208"></a><a class="code" href="a00035.html#a6a19e8ed9b796a93f8e0aeeaff22de83">00208</a>   <a class="code" href="a00088.html" title="May be published by MAC lyer to indicate why a packet was dropped.">DroppedPacket</a> <a class="code" href="a00035.html#a6a19e8ed9b796a93f8e0aeeaff22de83" title="Inspect reasons for dropped packets.">droppedPacket</a>;
<a name="l00209"></a>00209 
<a name="l00211"></a><a class="code" href="a00035.html#a5eb298197cc0eac3b5cd389b9dc4d88a">00211</a>   <span class="keywordtype">int</span> <a class="code" href="a00035.html#a5eb298197cc0eac3b5cd389b9dc4d88a" title="publish dropped packets nic wide">nicId</a>;
<a name="l00212"></a>00212 
<a name="l00214"></a><a class="code" href="a00035.html#acd3669a9dfbb2bc04d64f91ae8755a68">00214</a>   <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> <a class="code" href="a00035.html#acd3669a9dfbb2bc04d64f91ae8755a68" title="The maximum length of the queue.">queueLength</a>;
<a name="l00222"></a><a class="code" href="a00035.html#a344d41bb6a3dd348f0b193a253a44e63">00222</a>   <span class="keywordtype">bool</span> <a class="code" href="a00035.html#a344d41bb6a3dd348f0b193a253a44e63" title="Animate (colorize) the nodes.">animation</a>;
<a name="l00224"></a><a class="code" href="a00035.html#ad52c754e33e66f1811d4d0a52f748aea">00224</a>   <span class="keywordtype">double</span> <a class="code" href="a00035.html#ad52c754e33e66f1811d4d0a52f748aea" title="The duration of the slot in secs.">slotDuration</a>;
<a name="l00226"></a><a class="code" href="a00035.html#a30e8c5f8b0666509bec376dcc7dc057b">00226</a>   <span class="keywordtype">double</span> <a class="code" href="a00035.html#a30e8c5f8b0666509bec376dcc7dc057b" title="The bitrate of transmission.">bitrate</a>;
<a name="l00228"></a><a class="code" href="a00035.html#a6672d3d6469bf079cea9e9fc0430cfd7">00228</a>   <span class="keywordtype">double</span> <a class="code" href="a00035.html#a6672d3d6469bf079cea9e9fc0430cfd7" title="The duration of CCA.">checkInterval</a>;
<a name="l00230"></a><a class="code" href="a00035.html#a8507b0daed75036c14e6822cddb09832">00230</a>   <span class="keywordtype">double</span> <a class="code" href="a00035.html#a8507b0daed75036c14e6822cddb09832" title="Transmission power of the node.">txPower</a>;
<a name="l00232"></a><a class="code" href="a00035.html#ac44f7816182a2431558f281628808dbd">00232</a>   <span class="keywordtype">bool</span> <a class="code" href="a00035.html#ac44f7816182a2431558f281628808dbd" title="Use MAC level acks or not.">useMacAcks</a>;
<a name="l00235"></a><a class="code" href="a00035.html#ac89bcf80f1642195df80253067ba92e5">00235</a>   <span class="keywordtype">int</span> <a class="code" href="a00035.html#ac89bcf80f1642195df80253067ba92e5" title="Maximum transmission attempts per data packet, when ACKs are used.">maxTxAttempts</a>;
<a name="l00237"></a><a class="code" href="a00035.html#a3a94af09a9ad4145931583187c8cc793">00237</a>   <span class="keywordtype">bool</span> <a class="code" href="a00035.html#a3a94af09a9ad4145931583187c8cc793" title="Gather stats at the end of the simulation.">stats</a>;
<a name="l00238"></a>00238 
<a name="l00240"></a><a class="code" href="a00035.html#ab86d33b96584c398e40eb6ee973ce3e9">00240</a>   <span class="keyword">enum</span> <a class="code" href="a00035.html#ab86d33b96584c398e40eb6ee973ce3e9" title="Possible colors of the node for animation.">BMAC_COLORS</a> {
<a name="l00241"></a>00241     GREEN = 1,
<a name="l00242"></a>00242     BLUE = 2,
<a name="l00243"></a>00243     RED = 3,
<a name="l00244"></a>00244     BLACK = 4,
<a name="l00245"></a>00245     YELLOW = 5
<a name="l00246"></a>00246   };
<a name="l00247"></a>00247 
<a name="l00249"></a>00249   <span class="keywordtype">void</span> changeDisplayColor(BMAC_COLORS color);
<a name="l00250"></a>00250 
<a name="l00252"></a>00252   <span class="keywordtype">void</span> sendDataPacket();
<a name="l00253"></a>00253 
<a name="l00255"></a>00255   <span class="keywordtype">void</span> sendMacAck();
<a name="l00256"></a>00256 
<a name="l00258"></a>00258   <span class="keywordtype">void</span> sendPreamble();
<a name="l00259"></a>00259 
<a name="l00261"></a>00261   <span class="keywordtype">void</span> attachSignal(macpkt_ptr_t macPkt);
<a name="l00262"></a>00262 
<a name="l00264"></a>00264   <span class="keywordtype">bool</span> addToQueue(cMessage * msg);
<a name="l00265"></a>00265 };
<a name="l00266"></a>00266 
<a name="l00267"></a>00267 <span class="preprocessor">#endif </span><span class="comment">/* BMACLAYER_H_ */</span>
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><b>BMacLayer.h</b>      </li>

    <li class="footer">Generated on Tue Mar 5 2013 21:26:30 for MiXiM by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
